package com.midele.goodstuff.ui.record

import android.annotation.SuppressLint
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.constraintlayout.compose.Dimension
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import com.midele.goodstuff.R
import com.midele.goodstuff.ui.component.CommBackArrow
import com.midele.goodstuff.ui.component.CommConfirmDialog
import com.midele.goodstuff.ui.component.LeftIconTextRow
import com.midele.goodstuff.ui.theme.Black12
import com.midele.goodstuff.ui.theme.Black21
import com.midele.goodstuff.ui.theme.Gray64
import com.midele.goodstuff.ui.theme.WhiteDC
import com.midele.goodstuff.ui.theme.YellowFC
import com.midele.goodstuff.util.LogUtils
import com.midele.goodstuff.viewmodel.RecordFirstViewModel


@Composable
internal fun TrashBoxRoute(
    modifier: Modifier = Modifier,
    viewModel: RecordFirstViewModel = hiltViewModel(),
    navController: NavHostController,
) {
    TrashBoxScreen()
}

@Composable
fun TrashBoxScreen(
) {

    var isShowDeleteDialog = remember { mutableStateOf(false) }

    LogUtils.d("TrashBoxScreen","刷新 TrashBoxScreen>>>>>>>>>>>>")

    Column(
        modifier = Modifier
            .fillMaxSize()
            .background(Black12),
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {

        CommBackArrow(
            modifier = Modifier.fillMaxWidth(),
            title = stringResource(R.string.str_record_trash_box),
            onClick = {
                //navController.popBackStack()
            })
        Spacer(modifier = Modifier.height(16.dp))
        LazyColumn(
            modifier = Modifier
                .fillMaxSize()
                .padding(start = 16.dp, end = 16.dp)
        ) {
            LogUtils.d("TrashBoxScreen","更新列表 TrashBoxScreen>>>>>>>>>>>>")
            items(10) {
                LogUtils.d("TrashBoxScreen","items ${it}>>>>>>>>>>>>")
                ConstraintLayout(
                    modifier = Modifier
                        .fillMaxWidth()
                        .clip(RoundedCornerShape(16.dp))
                        .background(Black21)
                ) {
                    val (categoryTitleLayout, categoryValueLayout, typeTitleLayout, typeValueLayout, createTimeLayout, timeValueLayout, lineLayout, deleteLayout) = createRefs()
                    Text(
                        text = stringResource(R.string.str_record_good_category),
                        fontSize = 14.sp,
                        color = WhiteDC,
                        modifier = Modifier.constrainAs(categoryTitleLayout) {
                            top.linkTo(parent.top, 8.dp)
                            start.linkTo(parent.start, 16.dp)
                            width = Dimension.percent(0.3f)
                        }
                    )
                    Text(
                        text = "古珠",
                        fontSize = 14.sp,
                        color = Color.White,
                        fontWeight = FontWeight.Bold,
                        textAlign = TextAlign.End,
                        modifier = Modifier.constrainAs(categoryValueLayout) {
                            top.linkTo(categoryTitleLayout.top)
                            bottom.linkTo(categoryTitleLayout.bottom)
                            end.linkTo(parent.end,16.dp)
                            width = Dimension.percent(0.7f)
                        }
                    )
                    Text(
                        text = stringResource(R.string.str_record_good_type),
                        fontSize = 14.sp,
                        color = WhiteDC,
                        modifier = Modifier.constrainAs(typeTitleLayout) {
                            top.linkTo(categoryTitleLayout.bottom, 16.dp)
                            start.linkTo(parent.start, 16.dp)
                            width = Dimension.percent(0.3f)
                        }
                    )
                    Text(
                        text = "天珠",
                        fontSize = 14.sp,
                        color = Color.White,
                        fontWeight = FontWeight.Bold,
                        textAlign = TextAlign.End,
                        modifier = Modifier.constrainAs(typeValueLayout) {
                            top.linkTo(typeTitleLayout.top)
                            bottom.linkTo(typeTitleLayout.bottom)
                            end.linkTo(parent.end,16.dp)
                            width = Dimension.percent(0.7f)
                        }
                    )
                    Text(
                        text = stringResource(R.string.str_record_create_time),
                        fontSize = 14.sp,
                        color = WhiteDC,
                        modifier = Modifier.constrainAs(createTimeLayout) {
                            top.linkTo(typeTitleLayout.bottom, 16.dp)
                            start.linkTo(parent.start, 16.dp)
                            width = Dimension.percent(0.3f)
                        }
                    )
                    Text(
                        text = "2025-07-16 15:35-28",
                        fontSize = 14.sp,
                        color = Color.White,
                        fontWeight = FontWeight.Bold,
                        textAlign = TextAlign.End,
                        modifier = Modifier.constrainAs(timeValueLayout) {
                            top.linkTo(createTimeLayout.top)
                            bottom.linkTo(createTimeLayout.bottom)
                            end.linkTo(parent.end,16.dp)
                            width = Dimension.percent(0.7f)
                        }
                    )

                    Spacer(
                        modifier = Modifier.fillMaxWidth()
                            .height(0.5.dp)
                            .background(Gray64)
                            .constrainAs(lineLayout) {
                                top.linkTo(createTimeLayout.bottom, 16.dp)
                                start.linkTo(parent.start, 16.dp)
                                end.linkTo(parent.end, 16.dp)
                            })

                    LeftIconTextRow(
                        iconId = R.mipmap.ic_trash_box_delete,
                        text = stringResource(R.string.str_delete),
                        textColor = YellowFC,
                        textWeight = FontWeight.Bold,
                        spacing = 2.dp,
                        modifier = Modifier.constrainAs(deleteLayout) {
                            top.linkTo(lineLayout.bottom, 16.dp)
                            bottom.linkTo(parent.bottom, 16.dp)
                            end.linkTo(parent.end)
                            start.linkTo(parent.start)
                        },
                        onClick = {
                            //删除
                            isShowDeleteDialog.value = true
                        }
                    )
                }
                Spacer(
                    modifier = Modifier.height(16.dp))
            }
        }

    }

    if(isShowDeleteDialog.value){
        CommConfirmDialog(
            title = stringResource(R.string.str_delete_dialog_title),
            content = stringResource(R.string.str_delete_dialog_content),
            onDismissRequest = {
                //navController.popBackStack()
                isShowDeleteDialog.value = false
            },
            onConfirmation = {
                //navController.popBackStack()
                isShowDeleteDialog.value = false
            },
        )
    }

}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    TrashBoxScreen()
}

